#include "ADConverter.h"
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/stat.h> 
#include <linux/input.h> 
#include <unistd.h>

ADConverter::ADConverter(int channel)
{
	char channelStr[2];
	sprintf(channelStr, "%d", channel);
	strcpy(_deviceName, "/dev/adc");
	strcat(_deviceName, channelStr);

	_fd = 0;	
}

ADConverter::~ADConverter()
{
}

int ADConverter::openDevice()
{
	_fd = open(_deviceName, O_RDONLY | O_NONBLOCK);
	return _fd;
}

void ADConverter::closeDevice()
{
	close(_fd);
	_fd = 0;
}

int ADConverter::readDevice()
{
	char data[12];
	read(_fd, data, 12);
	return atoi(data);
}

int ADConverter::readString(char* dest)
{
	char data[2];
	int n = read(_fd, dest, 2);
	return n;
}
